import { request } from '@/service/request';
import { SysJob,SysJobLog } from "@/views/system/schedule-task/index";

export function fetchJob(id: Common.IdType) {
  return request({
    url: `/system/job/${id}`,
    method: 'GET',
  });
}

export function fetchJobPage(page: Common.Page<SysJob>, searchData: any) {
  return request({
    url: '/system/job/list',
    data: { page, searchData },
    method: 'POST',
  });
}

export function fetchAddJob(data: SysJob) {
  return request({
    url: '/system/job/',
    data: data,
    method: 'POST',
  });
}

export function fetchUpdateJob(data: SysJob) {
  return request({
    url: '/system/job/',
    data: data,
    method: 'PUT',
  });
}

export function fetchDelJob(ids: Common.IdType[]) {
  // 假设服务器端期望接收逗号分隔的 ID 字符串
  return request({
    url: `/system/job/${ids.join(',')}`,
    method: 'DELETE',
  });
}

export function fetchChangeStatus(id: number, status: string) {
  return request({
    url: `/system/job/changeStatus/${id}/${status}`,
    method: 'PUT',
  });
}

export function fetchExecuteOnce(id: number) {
  return request({
    url: `/system/job/executeOnce/${id}`,
    method: 'PUT',
  });
}

export function fetchJodLogPage(page: Common.Page<SysJobLog>, searchData: any) {
  return request({
    url: "/monitor/jobLog/list",
    method: 'POST',
    data: { page, searchData },
  });
}
